* to execute, nohup stata -b do melly_decomp_cons6 &
* batch mode: qsub batch.job
* status: qstat -u jsulliv4
* status: qstat -j [put job id]



set mem 2000m
set matsize 500

************************************************************************
* MERGE DATA FROM MICHAEL MURTO FOR 60S AND 80S WITH MASTER FILE
************************************************************************



use ~/jim/data/data_for_others/decomp_master, clear

append using ~/jim/data/data_for_others/decomp_60 
append using ~/jim/data/data_for_others/decomp_80

*keep if ref_year==1961 | ref_year==1972 | ref_year==1980 | ref_year==1990 | ref_year==2000 | ref_year==2017
*duplicates drop newid if ref_year==1972, force

sum

save master_final, replace


*********************************************************************************


foreach x in r_cons5 r_cons10 {
gen ln_`x'=ln(`x') if `x'>0
}


*********************************
* RUN DECOMPOSITION FOR 1961-1972
*********************************
preserve
keep if ref_year==1960 | ref_year==1961 | ref_year==1972
gen groupvar=1
replace groupvar=0 if ref_year==1960 | ref_year==1961
set seed 1

gen small_samp=uniform()
keep if ref_year==1972 | (ref_year==1961 & small_samp<.10)


*rqdeco3 ln_r_cons5 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

*rqdeco3 ln_r_cons10 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)


restore


*********************************
* RUN DECOMPOSITION FOR 1972-1980
*********************************
preserve
keep if ref_year==1972 | ref_year==1980
gen groupvar=1
replace groupvar=0 if ref_year==1972
set seed 1

gen small_samp=uniform()
keep if ref_year==1972 | (ref_year==1980 & small_samp<.10)

*rqdeco3 ln_r_cons5 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

*rqdeco3 ln_r_cons10 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

restore



*********************************
* RUN DECOMPOSITION FOR 1980-1990
*********************************
preserve
keep if ref_year==1980 | ref_year==1990
gen groupvar=1
replace groupvar=0 if ref_year==1980
set seed 1

gen small_samp=uniform()
keep if ref_year==1990 | (ref_year==1980 & small_samp<.10)


rqdeco3 ln_r_cons5 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

rqdeco3 ln_r_cons10 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

restore


*********************************
* RUN DECOMPOSITION FOR 1990-2000
*********************************
preserve
keep if ref_year==1990 | ref_year==2000
gen groupvar=1
replace groupvar=0 if ref_year==1990
set seed 1

rqdeco3 ln_r_cons5 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

rqdeco3 ln_r_cons10 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4)

restore


*********************************
* RUN DECOMPOSITION FOR 2000-2017
*********************************
preserve
keep if ref_year==2000 | ref_year==2017
gen groupvar=1
replace groupvar=0 if ref_year==2000
set seed 1

rqdeco3 ln_r_cons5 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4) 

rqdeco3 ln_r_cons10 age_ref age_ref_2 age_ref_3 fam2 fam3 fam4 fam5 race1 ed2 ed3 ed4 [pw=wgt20], by(groupvar) qlow(.1) qhigh(.9) qstep(.4) 

restore




